package com.tang.algorithm.ordinary;

/**
 * @author tlm
 * @Description
 * @date 2020/6/18 5:04 下午
 */
public class LeetCode1323 {
    public static void main(String[] args) {
        LeetCode1323 leetCode1323 = new LeetCode1323();
        System.out.println(leetCode1323.maximum69Number(6699));
    }

    public int maximum69Number(int num) {
        int size = 0;
        int[] res = new int[4];
        while (num > 0) {
            res[size] = num % 10;
            num = num / 10;
            size++;
        }
        int result = 0;
        boolean flag = false;
        for (int i = size - 1; i >= 0; i--) {
            if (res[i] != 9 && !flag) {
                res[i] = 9;
                flag = true;
            }
            result += res[i] * Math.pow(10, i);
        }
        return result;
    }
}
